package kankeba;

import javax.swing.text.html.HTMLDocument;
import java.util.*;

public class Main {

        public static void main(String[] args) {
            Scanner scanner=new Scanner(System.in);
            int arr[]={1,2,3,4,5};
            int arr1[]={3,5,7,9,11};
            int a[]=findTopKinTwoSortedArray(arr,arr1,4);
            for(int i=0;i<a.length;i++){
                System.out.println(a[i]);
            }



        }
    public static int[] findTopKinTwoSortedArray (int[] arr1, int[] arr2, int k) {
            int n=arr1.length;
            int m=arr2.length;
            int a[]=new int[k];
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>();
           for(int i=n-1;i>=n-k;i--){
               for(int j=m-1;j>=m-k;j--){

                   if(priorityQueue.size()<k){
                       int s= arr1[i]+arr2[j];
                       priorityQueue.add(s);
                   }
                   else {
                       int m1=(arr1[i]+arr2[j]);
                       if(priorityQueue.peek()<m1){
                           priorityQueue.poll();
                           priorityQueue.add(m1);
                       }
                   }
               }
           }
           for(int i=k-1;i>=0;i--){
               if(priorityQueue.size()!=0) {
                   a[i] = priorityQueue.poll();
               }
           }
            return  a;
    }
    public int minEditCost (String str1, String str2, int ic, int dc, int rc) {
        // write code here
        int m=ic+dc;
        int n=rc;
        int s1=str1.length();
        int s2=str2.length();
        if(m>n){

        }
 return 0;
    }
    public int findtheNumber (int[] arr, int k) {
        // write code here
        HashMap<Integer,Integer> hashMap=new HashMap<>();
        for(int i=0;i<arr.length;i++){
            if(hashMap.containsKey(arr[i])){
                int n=hashMap.get(arr[i]);
                hashMap.put(arr[i],n+1);
            }
            else
                hashMap.put(arr[i],1);
        }
        Iterator iterator=hashMap.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<Integer,Integer> entry=(Map.Entry<Integer, Integer>) iterator.next();
            if(entry.getValue()==1){
                return entry.getKey();
            }
        }
        return 0;
    }

}